package com.chcit.mobile.mvp.model;

import android.app.Application;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.chcit.mobile.mvp.model.api.cache.CommonCache;
import com.chcit.mobile.mvp.model.api.service.CommonService;
import com.chcit.mobile.mvp.model.api.service.UserService;
import com.chcit.mobile.mvp.model.entity.BpartnerBean;
import com.chcit.mobile.mvp.model.entity.Statu;
import com.chcit.mobile.mvp.model.entity.StorageBean;
import com.google.gson.Gson;
import com.jess.arms.integration.IRepositoryManager;
import com.jess.arms.mvp.BaseModel;
import com.jess.arms.di.scope.FragmentScope;

import javax.inject.Inject;

import com.chcit.mobile.mvp.contract.InventoryContract;
import java.util.List;
import io.reactivex.Observable;
import io.reactivex.ObservableSource;
import io.reactivex.functions.Function;
import io.rx_cache2.DynamicKey;
import io.rx_cache2.EvictProvider;



@FragmentScope
public class InventoryModel extends BaseModel implements InventoryContract.Model {
    @Inject
    Gson mGson;
    @Inject
    Application mApplication;

    @Inject
    public InventoryModel(IRepositoryManager repositoryManager) {
        super(repositoryManager);
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        this.mGson = null;
        this.mApplication = null;
    }

    @Override
    public Observable<List<StorageBean>> getData(JSONObject json) {
        return mRepositoryManager.obtainRetrofitService(UserService.class)
                .queryStorage(json)
                .map(jsonObject -> {
                    JSONArray jsonArray =  jsonObject.getJSONArray("rows");
                    return jsonArray.toJavaList(StorageBean.class);
                });
    }




}